package 贪心;

import org.junit.Test;

import java.util.Arrays;
import java.util.PriorityQueue;

/**
 * @author aodre , QQ : 480029069
 * @date 2023/9/11 14:37
 */
public class lc630课程表III {




    public int solve(int courses[][]){

        return 0;

    }
    public int[] smallestK(int nums[], int k) {
        if(k == 0){
            return new int[]{};
        }
        PriorityQueue<Integer> queue = new PriorityQueue<>((a,b)-> b - a);
        for(int i = 0;i < nums.length;i++){
            if(queue.size() < k){
                queue.add(nums[i]);
            }else if(queue.peek() > nums[i]){
                queue.poll();
                queue.add(nums[i]);
            }
        }
        int ans[] = new int [k];
        int index = 0;
        for(int num : queue){
            ans[index ++] = num;
        }
        return ans;
    }


    @Test
    public void test(){
        int nums[] = {1,3,5,7,2,4,6,8};
        int k = 4;
        int[] ints = smallestK(nums, k);
        System.out.println(Arrays.toString(ints));
    }



}
